/* 
 * File:   Door.cpp
 * Author: fabienlenoir
 * 
 * Created on September 18, 2009, 8:21 AM
 */

#include "Door.h"

using namespace std;



Door::Door(const unsigned int posX, const unsigned int posY) : Tile(posX, posY) {
    _open = false;
}   

Door::Door(const Door& orig) {
}

Door::~Door() {
}

void Door::enter(Movable *m) {
    if (isOpen()) {
        Tile::enter(m);
    } else {
        open();
        paint(View::instance());
    }
}

void Door::paint(View* v) const {
    if (isOpen())
        v->drawGraphic(getPosition(), "door_open");
    else
        v->drawGraphic(getPosition(), "door_closed");

    if(_content != 0) {
        _content->paint(v);
    }
}

MapSite* Door::clone(unsigned int x, unsigned int y) const {
    return new Door(x, y);
}

MapSite::MS_TYPE Door::getType() const{
    return MS_DOOR;
}

bool Door::isOpen() const{
    return _open;
}

bool Door::isClosed() const{
    return !isOpen();
}

void Door::open() {
    _open = true;
}

void Door::close() {
    _open = false;
}